package com.fh.utils;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

/**
 * @author whf
 * @date 2023年04月25日 16:16
 */
@Component
public class SixSecretKey {
    public static final byte[] api = SecretKey();
    @Scheduled(fixedRate = 6 * 60 * 1000)
    public static byte[] SecretKey(){
        try {
            KeyGenerator keyGen = KeyGenerator.getInstance("AES");
            int keySize = 256;
            SecureRandom random = new SecureRandom();
            keyGen.init(keySize, random);
            SecretKey secretKey = keyGen.generateKey();
            return secretKey.getEncoded();
        } catch(NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }


}
